# -*- coding: utf-8 -*-
# FileName:     zweb.py
# Time:         23/5/19 019 下午 10:48
# Author:       Zhou Hang
# Description:  I don't want to write.
import os
import urllib3

UPLOAD_API = "http://47.100.107.53:10180/audio/upload"
# UPLOAD_API = "http://localhost:10180/audio/upload"


def upload_wav(filepath):
    """
    向后端发送wav文件
    :param filepath:
    :return:
    """
    if filepath.endswith(".wav"):
        filename = os.path.basename(filepath)
        with open(filepath, "rb") as fp:
            file_data = fp.read()
        fields = {
            "files": (filename, file_data, "audio/wav")
        }
        http = urllib3.PoolManager()
        resp = http.request("POST",
                            UPLOAD_API,
                            fields=fields
                            )
        print(resp.status)
        print(resp.data)
        return resp


def main():
    resp = upload_wav("../../output/records/2023-5-19-20-34-39.wav")
    print(resp.status)
    print(resp.data)


if __name__ == "__main__":
    main()
